/**
 * 
 */
package co.gov.medellin.sdep.sisdep.operativa.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.operativa.exception.CharlaPProgException;
import co.gov.medellin.sdep.sisdep.operativa.exception.CharlaPProgRuntimeException;
import co.gov.medellin.sdep.sisdep.operativa.exception.CitacionException;
import co.gov.medellin.sdep.sisdep.operativa.exception.CitacionRuntimeException;
import co.gov.medellin.sdep.sisdep.operativa.exception.descriptor.CharlaPProgMessageDescriptor;
import co.gov.medellin.sdep.sisdep.operativa.exception.descriptor.CitacionMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.CharlaPProg;
import co.gov.medellin.sdep.sisdep.model.Citacion;
import co.gov.medellin.sdep.sisdep.model.dao.impl.ICharlaPProgDAOT;

/**
 * @author Usuario
 *
 */
public class CharlaPProgServiceImpl extends BaseService implements ICharlaPProgService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private ICharlaPProgDAOT charlaPProgDAO;

	/**
	 * 
	 */
	public CharlaPProgServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(CharlaPProg charlaPProg) throws CharlaPProgException {
		try{
			charlaPProg.setUsuarioCrea(getPrincipalUser());
			charlaPProg.setFechaCrea(new Date());
			getCharlaPProgDAO().insert(charlaPProg);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new CharlaPProgException(new CharlaPProgMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new CharlaPProgException(new CharlaPProgMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(CharlaPProg charlaPProg) throws CharlaPProgException {
		try{
			charlaPProg.setUsuarioModifica(getPrincipalUser());
			charlaPProg.setFechaModifica(new Date());
			getCharlaPProgDAO().update(charlaPProg);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new CharlaPProgRuntimeException(new CharlaPProgMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new CharlaPProgRuntimeException(new CharlaPProgMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(CharlaPProg charlaPProg) throws CharlaPProgException {
		try {
			charlaPProg.setUsuarioModifica(getPrincipalUser());
			charlaPProg.setFechaModifica(new Date());
			getCharlaPProgDAO().delete(charlaPProg);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new CharlaPProgRuntimeException(new CharlaPProgMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, CharlaPProg charlaPProg) throws CharlaPProgException {
		try{
			//return getCharlaPProgDAO().getAllCharlaPProgPaginated(start, max, criteria);
			return getCharlaPProgDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new CharlaPProgRuntimeException(new CharlaPProgMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final List loadByTipoCharla(int start,int max, CharlaPProg charlaPProg) throws CharlaPProgException {
		try{
			//return getCharlaPProgDAO().getAllCharlaPProgPaginated(start, max, criteria);
			return getCharlaPProgDAO().loadByTipoCharla(charlaPProg);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new CharlaPProgRuntimeException(new CharlaPProgMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}


	/**
	 * 
	 */
	public final CharlaPProg get(long id) throws CharlaPProgException {
		try{
			return getCharlaPProgDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new CharlaPProgRuntimeException(new CharlaPProgMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final String verificarDocumento(CharlaPProg charlaPProg) throws CharlaPProgException {
		try{
			//return getCitacionDAO().getAllCitacionPaginated(start, max, criteria);
			return getCharlaPProgDAO().verificarDocumento(charlaPProg);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new CitacionRuntimeException(new CitacionMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public ICharlaPProgDAOT getCharlaPProgDAO() {
		return charlaPProgDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setCharlaPProgDAO(ICharlaPProgDAOT charlaPProgDAO) {
		this.charlaPProgDAO = charlaPProgDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
